WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
landmark_base.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21// Wolf includes
22#include "core/common/wolf.h"
26
27// yaml
28#include "yaml-schema-cpp/yaml_server.hpp"
29
30namespace wolf
31{
32/*
33 * Macro for defining Autoconf landmark creator.
34 *
35 * Place a call to this macro inside your class declaration (in the landmark_class.h file),
36 * preferably just after the constructors. Inside 'public' keyword.
37 *
38 * In order to use this macro, the derived landmark class, LandmarkClass,
39 * must have two constructors available with the API:
40 *
41 * LandmarkClass(const YAML::Node& _node);
42 *
43 * Also, there should be the schema file 'LandmarkClass.schema' containing the specifications
44 * of the user input yaml file.
45 *
46 * NOTE: We use `new` and not `make_shared` since the constructor may (should) be private/protected
47 */
48#define WOLF_LANDMARK_CREATE(LandmarkClass) \
49 static LandmarkBasePtr create(const YAML::Node& _node, const std::vector<std::string>& _folders_schema = {}) \
50 { \
51 if (not _folders_schema.empty()) \
52 { \
53 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
54 server.setYaml(_node); \
55 if (not server.applySchema(#LandmarkClass)) \
56 { \
57 WOLF_ERROR(server.getLog()); \
58 return nullptr; \
59 } \
60 std::shared_ptr<LandmarkClass> lmk(new LandmarkClass(server.getNode())); \
61 lmk->emplacePriors(); \
62 return lmk; \
63 } \
64 std::shared_ptr<LandmarkClass> lmk(new LandmarkClass(_node)); \
65 lmk->emplacePriors(); \
66 return lmk; \
67 }
68
69#define WOLF_LANDMARK_TEMPLATE_DIM_CREATE(LandmarkClass, Dim) \
70 static LandmarkBasePtr create(const YAML::Node& _node, const std::vector<std::string>& _folders_schema = {}) \
71 { \
72 if (not _folders_schema.empty()) \
73 { \
74 auto server = yaml_schema_cpp::YamlServer(_folders_schema); \
75 server.setYaml(_node); \
76 if (not server.applySchema(#LandmarkClass + std::to_string(Dim) + "d")) \
77 { \
78 WOLF_ERROR(server.getLog()); \
79 return nullptr; \
80 } \
81 std::shared_ptr<LandmarkClass<Dim>> lmk(new LandmarkClass<Dim>(server.getNode())); \
82 lmk->emplacePriors(); \
83 return lmk; \
84 } \
85 std::shared_ptr<LandmarkClass<Dim>> lmk(new LandmarkClass<Dim>(_node)); \
86 lmk->emplacePriors(); \
87 return lmk; \
88 }
89
90// class LandmarkBase
92{
93 friend FactorBase;
94
95 private:
96 MapBaseWPtr map_ptr_;
97 static unsigned int landmark_id_count_;
98
99 protected:
100 unsigned int landmark_id_;
101 unsigned int track_id_;
105
106 // Navigate wolf tree
107 void setProblem(ProblemPtr _problem) override;
108
109 public:
124 LandmarkBase(const std::string& _type,
125 const TypeComposite& _state_types,
126 const VectorComposite& _state_vectors,
127 const PriorComposite& _state_priors,
128 const int _external_id = -1,
129 const int _external_type = -1);
130
139 LandmarkBase(const std::string& _type, const TypeComposite& _state_types, const YAML::Node& _n);
140
141 ~LandmarkBase() override = default;
142 void remove(bool viral_remove_parent_without_children = false) override;
143
144 YAML::Node toYaml() const override;
145
146 // Properties
147 unsigned int id() const override;
148 void setId(unsigned int _id);
149
150 unsigned int trackId(); // get track ID
151 void setTrackId(unsigned int _track_id); // set track ID
152
153 void setExternalId(const int& _external_id);
154 int getExternalId() const;
155 void setExternalType(const int& _external_type);
156 int getExternalType() const;
157
158 MapBaseConstPtr getMap() const;
159 MapBasePtr getMap();
160
161 void link(MapBasePtr);
162 template <typename classType, typename... T>
163 static std::shared_ptr<classType> emplace(MapBasePtr _map_ptr, T&&... all);
164
165 virtual void printHeader(int depth, //
166 bool factored_by, //
167 bool metric, //
168 bool state_blocks,
169 std::ostream& stream,
170 std::string _tabs = "") const;
171
172 virtual void print(int depth, //
173 bool factored_by, //
174 bool metric, //
175 bool state_blocks,
176 std::ostream& stream = std::cout,
177 std::string _tabs = "") const;
178
179 virtual CheckLog localCheck(bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
180 virtual bool check(CheckLog& _log, bool _verbose, std::ostream& _stream, std::string _tabs = "") const;
181
182 private:
183 void setMap(const MapBasePtr _map_ptr);
184
185 public:
186 LandmarkBasePtr shared_from_this_landmark();
187 LandmarkBaseConstPtr shared_from_this_landmark() const;
188};
189} // namespace wolf
190
191#include "core/map/map_base.h"
194
195namespace wolf
196{
197template <typename classType, typename... T>
198std::shared_ptr<classType> LandmarkBase::emplace(MapBasePtr _map_ptr, T&&... all)
199{
200 std::shared_ptr<classType> lmk = std::make_shared<classType>(std::forward<T>(all)...);
201 lmk->emplacePriors();
202 lmk->link(_map_ptr);
203 return lmk;
204}
205
206inline MapBaseConstPtr LandmarkBase::getMap() const
207{
208 return map_ptr_.lock();
209}
210
211inline MapBasePtr LandmarkBase::getMap()
212{
213 return map_ptr_.lock();
214}
215
216inline void LandmarkBase::setMap(const MapBasePtr _map_ptr)
217{
218 map_ptr_ = _map_ptr;
219}
220
221inline unsigned int LandmarkBase::id() const
222{
223 return landmark_id_;
224}
225
226inline void LandmarkBase::setId(unsigned int _id)
227{
228 landmark_id_ = _id;
229 if (_id > landmark_id_count_) landmark_id_count_ = _id;
230}
231
232inline unsigned int LandmarkBase::trackId()
233{
234 return track_id_;
235}
236
237inline void LandmarkBase::setTrackId(unsigned int _track_id)
238{
239 track_id_ = _track_id;
240}
241
242inline void LandmarkBase::setExternalId(const int& _external_id)
243{
244 external_id_ = _external_id;
245}
246
248{
249 return external_id_;
250}
251
252inline void LandmarkBase::setExternalType(const int& _external_type)
253{
254 external_type_ = _external_type;
255}
256
258{
259 return external_type_;
260}
261
263{
264 return std::static_pointer_cast<LandmarkBase>(shared_from_this());
265}
266
267inline LandmarkBaseConstPtr LandmarkBase::shared_from_this_landmark() const
268{
269 return std::static_pointer_cast<const LandmarkBase>(shared_from_this());
270}
271
272} // namespace wolf
Definition: check_log.h:28
Definition: factor_base.h:72
Definition: landmark_base.h:92
void setProblem(ProblemPtr _problem) override
Definition: landmark_base.cpp:107
int getExternalId() const
Definition: landmark_base.h:247
unsigned int track_id_
associated track id
Definition: landmark_base.h:101
int external_type_
Type provided by an external classifier (-1 unclassified)
Definition: landmark_base.h:103
int external_id_
Id provided by an external tracker (-1 untracked)
Definition: landmark_base.h:102
void setTrackId(unsigned int _track_id)
Definition: landmark_base.h:237
unsigned int id() const override
Definition: landmark_base.h:221
LandmarkBase(const std::string &_type, const TypeComposite &_state_types, const VectorComposite &_state_vectors, const PriorComposite &_state_priors, const int _external_id=-1, const int _external_type=-1)
Constructor type and state specs composites (types, vectors, priors)
Definition: landmark_base.cpp:28
virtual void print(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream=std::cout, std::string _tabs="") const
Definition: landmark_base.cpp:133
MapBaseConstPtr getMap() const
Definition: landmark_base.h:206
int getExternalType() const
Definition: landmark_base.h:257
unsigned int landmark_id_
landmark unique id
Definition: landmark_base.h:100
YAML::Node toYaml() const override
Definition: landmark_base.cpp:77
virtual void printHeader(int depth, bool factored_by, bool metric, bool state_blocks, std::ostream &stream, std::string _tabs="") const
Definition: landmark_base.cpp:114
void setExternalType(const int &_external_type)
Definition: landmark_base.h:252
void remove(bool viral_remove_parent_without_children=false) override
Definition: landmark_base.cpp:57
LandmarkBasePtr shared_from_this_landmark()
Definition: landmark_base.h:262
virtual bool check(CheckLog &_log, bool _verbose, std::ostream &_stream, std::string _tabs="") const
Definition: landmark_base.cpp:174
virtual CheckLog localCheck(bool _verbose, std::ostream &_stream, std::string _tabs="") const
Definition: landmark_base.cpp:143
TimeStamp stamp_
stamp of the creation of the landmark
Definition: landmark_base.h:104
void link(MapBasePtr)
Definition: landmark_base.cpp:90
void setId(unsigned int _id)
Definition: landmark_base.h:226
~LandmarkBase() override=default
unsigned int trackId()
Definition: landmark_base.h:232
void setExternalId(const int &_external_id)
Definition: landmark_base.h:242
static std::shared_ptr< classType > emplace(MapBasePtr _map_ptr, T &&... all)
Definition: landmark_base.h:198
Definition: node_state_blocks.h:32
TimeStamp implements basic functionalities for time stamps.
Definition: time_stamp.h:39
Definition: vector_composite.h:27
Definition: capture_base.h:23